var submit = document.querySelector(".submit");
var cpdetails = document.querySelector("[name=cpdetails]");
var myname = document.querySelector("[name=myname]");
var mytel = document.querySelector("[name=mytel]");
var myemail = document.querySelector("[name=myemail]");
var content = document.querySelector("[name=content]");
var vcode = document.querySelector("[name=vcode]");


var form = document.querySelector(".form");
submit.onclick = function(){
	var errorText;
	var myemailreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
	var mytelreg = /^1[3|4|5|7|8]\d{9}$/;
	if(cpdetails.value==""){
		errorText = "请输入公司信息！";
	}else if(myname.value==""){
		errorText = "请输入您的姓名！";
	}else if(mytel.value==""){
		errorText = "请输入您的联系电话！";
	}else if(myemail.value==""){
		errorText = "请输入您的邮箱！";
	}else if(content.value==""){
		errorText = "请输入您需求！";
	}else if(vcode.value==""){
		errorText = "请输入验证码！";
	}else if(!mytelreg.test(mytel.value)){
		errorText = "请输入正确的电话号码！";
	}else if(!myemailreg.test(myemail.value)){
		errorText = "请输入正确的邮箱！";
	}
	if(errorText != undefined){
		addErrorText(errorText);
	}
	
};

function addErrorText(errorText){
	var error_div = document.createElement("div");
	error_div.setAttribute('class','error'); 
	error_div.innerText = errorText;
	form.appendChild(error_div);
	
	time = setTimeout(function(){
		form.removeChild(error_div)
	},2000)
}